package com.cneiu.ppms.web.service;

import java.util.List;
import java.util.Map;


import com.cneiu.ppms.web.base.BaseService;
import com.cneiu.ppms.web.model.MenuRoleModel;
import com.jfinal.plugin.activerecord.Db;
/**
 * 菜单角色业务
 * @author zhaokf
 * @date 2013-04-22
 */
public class MenuRoleService extends BaseService
{
	/**
	 * 添加菜单角色
	 * @param params
	 * @return
	 */
	public static boolean isAdd(Map<String,String> params){
		String SQL = "insert into sa_menu_role(mr_role_no,mr_menu_no) values(?,?)";
		int isupadded = Db.update(SQL, params.get("mr_role_no"),params.get("mr_menu_no"));
		if(isupadded==1){
			return true;
		}
		return setError("保存菜单角色失败！");
	}

	/**
	 * 根据用户ID查询菜单角色
	 * @param params
	 * @return
	 */
	public static List<MenuRoleModel> get(Map<String,String> params){
		String no = params.get("mr_role_no")==null?"":params.get("mr_role_no").toString();
		List<MenuRoleModel> mr = MenuRoleModel.dao.find("SELECT * FROM SA_MENU_ROLE  WHERE MR_ROLE_NO=?", no);
		return mr;
	}

	/**
	 * 删除菜单角色
	 * @param params
	 * @return
	 */
	public static boolean isDelete(Map<String,String> params){
		String SQL = "DELETE FROM SA_MENU_ROLE WHERE MR_ROLE_NO=? AND MR_MENU_NO=?";
		int deleted = Db.update(SQL, params.get("mr_role_no"),params.get("mr_menu_no"));
		if (deleted==1){
			return true;
		}
		return setError("您访问的菜单角色不存在！");
	}
}


